﻿@model Himall.Core.Plugins.FormData

<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>消息设置</strong>
        <li value=""><a href="@Url.Action("management","message")">管理</a></li>
        @foreach (var messagePlugin in @ViewBag.messagePlugins)
        {
            var active = @messagePlugin.pluginId == @ViewBag.Id ? "active" : "";
            <li class="@active"><a href="edit?pluginId=@(messagePlugin.pluginId)">@{@messagePlugin.name}配置</a></li>
        }
        <em class="primary-btn">
            <span class="glyphicon glyphicon-question-sign"></span>
            <div class="primary">
                <h3>温馨提示：</h3>
                <span>*</span><p>你可以在此设置短信、邮件等消息</p>
            </div>
        </em>
    </ul>
    <div class="form-horizontal">
        @if (@ViewBag.ShowSMS)
        { <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <span class="help-default">首次使用需要注册短信平台，并获取短信接口的Appkey和Appsecret <a target="_blank" href="@ViewBag.LoginLink">点击此处</a></span>
              </div>
			
        </div>
        }
        @if (@ViewBag.ShowBuy)
        {<div class="form-group">
			<label class="col-sm-2 control-label" for="">平台剩余短信：</label>
            <div class="col-sm-3 form-control-static">
                @ViewBag.Amount 条  <a target="_blank" href="@ViewBag.BuyLink">购买</a>
            </div>
        </div>
        }
        @foreach (var item in Model.Items)
        {
            <div class="form-group">
                <label class="col-sm-2 control-label" for="">@item.DisplayName:</label>
                <div class="col-sm-3">
                    @{
            if (item.Type == Himall.Core.Plugins.FormData.FormItemType.text)
            {
                <input formitem name="@item.Name" type="text" value="@item.Value" class="form-control input-sm" />
            }
            else if (item.Type == Himall.Core.Plugins.FormData.FormItemType.password)
            {
                <input formitem name="@item.Name" type="password" value="@item.Value" class="form-control input-sm" />
            }
            else
            {
                <input formitem name="@item.Name" type="checkbox" value="@item.Value" class="form-control input-sm" />
            }
                    }
                </div>
            </div>
        }
        <input type="hidden" id="pluginId" value="@ViewBag.Id" />

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="button" id="btn" class="btn btn-primary" value="保 存" />
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label" for="">测试接收 @ViewBag.ShortName :</label>
            <div class="col-sm-3">
                <input id="destination" name="destination" type="text" class="form-control input-sm" />
            </div>
			<div class="col-sm-3"><input type="button" id="btnsend" class="btn btn-default btn-sm" value="开始测试" /></div>
        </div>
    </div>
</div>


<script>
    $(function () {
        $('#btn').click(function () {
            var items = $('input[formItem]');
            var data = [];
            $.each(items, function (i, item) {
                data.push({ key: $(item).attr('name'), value: $(item).val() });
            });
            var dataString = JSON.stringify(data);
            var id = $('#pluginId').val();
            var loading = showLoading();
            $.post('save', { pluginId: id, values: dataString }, function (result) {
                if (result.success)
                    $.dialog.succeedTips('保存成功！', function () { });
                else
                    $.dialog.errorTips('保存失败！' + result.msg);
                loading.close();
            });
        });

    });

    $('#btnsend').click(function () {
        var destination = $("#destination").val();
        var id = $('#pluginId').val();
        var loading = showLoading();
        $.post('send', { pluginId: id, destination: destination }, function (result) {
            if (result.success) {
                $.dialog.succeedTips('测试成功！');
                loading.close();
            }
            else {
                $.dialog.errorTips('测试失败！' + result.msg);
                loading.close();
            }
        });
    });
</script>


